
#include "http_post.h"

const char *ssid = "Epic";
const char *password = "cqupt3g666";
const char *host = "http://192.168.137.1:9912/data";
void WifiInit()
{
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }
}
void sendValues(float temp_dirty, float temp_clear,
                float ph_dirty, float ph_clear,
                u16_t ntu_dirty, u16_t ntu_clear,
                float ppm_dirty, float ppm_clear)
{

    // read_temp(&temp_dirty, &temp_clear);
    // printf("temp1: %f", &temp1);
    // printf("temp2: %f", &temp2);
    char send_data[128];
sprintf(send_data,
          "{\"temp\":[%.2f,%.2f],\"ph\":[%.2f, %.2f],\"ntu\": [%hu, %hu],\"ppm\":[%.2f,%.2f]}",
          temp_dirty, temp_clear, ph_dirty, ph_clear, ntu_dirty, ntu_clear, ppm_dirty, ppm_clear);

    HTTPClient http;
    http.begin(host);
    http.POST(send_data);
    // int httpCode = http.POST(send_data);
    // if (httpCode > 0)
    //     Serial.printf("[HTTP] POST... code: %d\n", httpCode);
    // else
    //     Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
    http.end();
}

#ifdef http_post

// const int httpPort = 9912;

void setup()
{
    Serial.begin(9600);
    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }
}

void loop()
{
    float temp1, temp2;
    char send_data[100];
    read_temp(&temp1, &temp2);
    // printf("temp1: %f", &temp1);
    // printf("temp2: %f", &temp2);
    sprintf(send_data, "{\"ph\":[10, 9],\"tds\": [100, 255],\"temp\":[%2f,%2f],\"turb\":[3000,40000]}", temp1, temp2);
    // Serial.println(send_data);
    HTTPClient http;

    http.begin(host);
    int httpCode = http.POST(send_data);

    if (httpCode > 0)
        Serial.printf("[HTTP] POST... code: %d\n", httpCode);
    else
        Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());

    http.end();

    delay(1000);
}
#endif